home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 13 / MacFormat n. 13 (Spain) / Macformat 13.bin / Shareware Internet / Desarrolladores / ICAppSourceKit1.2 / ICStandardFile.p < prev    next >
Encoding:
Text File  |  1995-11-07  |  3.0 KB  |  121 lines

  1. unit ICStandardFile;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Files;
  7.         
  8.     function ICStandardGetFile (t: OSType; var fs: FSSpec; var fi: FInfo): OSErr;
  9.     function ICStandardPutFile (prompt, name: str255; var fs: FSSpec): OSErr;
  10.     function ICStandardGetFolder (var fs: FSSpec; var dirID: longInt): OSErr;
  11.  
  12. implementation
  13.  
  14.     uses
  15.         Finder, StandardFile, ICGlobals, ICMiscSubs, StandardGetFolder;
  16.  
  17.     function ICStandardGetFile (t: OSType; var fs: FSSpec; var fi: FInfo): OSErr;
  18.         var
  19.             tl: SFTypeList;
  20.             reply: SFReply;
  21.             types: integer;
  22.             err: OSErr;
  23.             junklong: longInt;
  24.             nreply: StandardFileReply;
  25.     begin
  26.         tl[0] := t;
  27.         if t = OSType(0) then begin
  28.             types := -1;
  29.         end else if t = 'APPL' then begin
  30.             tl[1] := kApplicationAliasType;
  31.             types := 2;
  32.         end else begin
  33.             types := 1;
  34.         end;
  35.         err := userCanceledErr;
  36.         if has_newStdFile then begin
  37.             StandardGetFile(nil, types, @tl, nreply);
  38.             if nreply.sfGood then begin
  39.                 fs := nreply.sfFile;
  40.                 err := HGetFInfo(fs.vRefNum, fs.parID, fs.name, fi);
  41.             end;
  42.         end else begin
  43.             SFGetFile(Point($00640064), '', nil, types, @tl, nil, reply);
  44.             if reply.good then begin
  45.                 err := GetFInfo(reply.fName, reply.vRefNum, fi);
  46.                 if err = noErr then begin
  47.                     fs.name := reply.fName;
  48.                     err := GetWDinfo(reply.vRefNum, fs.vRefNum, fs.parID, junklong);
  49.                 end;
  50.             end;
  51.         end;
  52.         ICStandardGetFile := err;
  53.     end;
  54.  
  55.     function ICStandardPutFile (prompt, name: str255; var fs: FSSpec): OSErr;
  56.         var
  57.             reply: SFReply;
  58.             err: OSErr;
  59.             junklong: longInt;
  60.             nreply: StandardFileReply;
  61.     begin
  62.         err := userCanceledErr;
  63.         if has_newStdFile then begin
  64.             StandardPutFile(prompt, name, nreply);
  65.             if nreply.sfGood then begin
  66.                 fs := nreply.sfFile;
  67.                 err := noErr;
  68.             end;
  69.         end else begin
  70.             SFPutFile(Point($00640064), prompt, name, nil, reply);
  71.             if reply.good then begin
  72.                 fs.name := reply.fName;
  73.                 err := GetWDinfo(reply.vRefNum, fs.vRefNum, fs.parID, junklong);
  74.             end;
  75.         end;
  76.         ICStandardPutFile := err;
  77.     end;
  78.  
  79.     function ButtonHook (item: integer; dlg: DialogPtr): integer;
  80.     begin
  81.         dlg := dlg; { Unused }
  82.         if item = 11 then begin
  83.             item := sfItemOpenButton;
  84.         end;
  85.         ButtonHook := item;
  86.     end;
  87.  
  88.     function ICStandardGetFolder (var fs: FSSpec; var dirID: longInt): OSErr;
  89.         var
  90.             err: OSErr;
  91.             typelist: SFTypeList;
  92.             cpb: CInfoPBRec;
  93.             reply: SFReply;
  94.             junklong: longInt;
  95.             nreply: StandardFileReply;
  96.     begin
  97.         err := userCanceledErr;
  98.         if has_newStdFile then begin
  99.             StandardGetFolder(Point($00640064), '', nreply);
  100.             if nreply.sfGood then begin
  101.                 fs := nreply.sfFile;
  102.                 err := noErr;
  103.             end;
  104.         end else begin
  105.             typeList[0] := OSType(0); { numTypes=0 doesn't seem to stop files from being displayed }
  106.             SFPGetFile(Point($00640064), '', nil, 1, @typeList, @ButtonHook, reply, 1500, nil);
  107.             if reply.good then begin
  108.                 err := GetWDinfo(reply.vRefNum, fs.vRefNum, fs.parID, junklong);
  109.             end; (* if *)
  110.         end;
  111.         if err = noErr then begin
  112.             err := FSpGetCatInfo(fs, -1, cpb);
  113.             if err = noErr then begin
  114.                 fs.parID := cpb.ioDrParID;
  115.                 dirID := cpb.ioDirID;
  116.             end; (* if *)
  117.         end;
  118.         ICStandardGetFolder := err;
  119.     end;
  120.  
  121. end.